﻿using System;
using System.Collections;
using System.Data;
using System.Windows.Forms;
using System.Xml;
using ZYCommon;

namespace TextEditor
{
    
   
    

    public class KB_List : ZYDBRecordBase, IListIndex
    {
        private bool bolShowInTree = true;
        public string ChineseSpell = null;
        public bool HasLaunchSystemItems = false;
        private int intKBStyle = 0;
        private int intListIndex = 0;
        private ArrayList myChildNodes = null;//孩子结点
        private ArrayList myItems = null;//具体的选项
        private KB_List myParent = null;//父节点
        public int RefCount = 0;
        public static string strDeptment;//
        private string strDesc = " ";//结点描述(单位) 
        private string strFullPath = null;//完整路径
        private string strKBGroup = "";//属于哪一个组
        private string strListSQL = " ";//sql语句(KB_List表中对应列)
        private string strName = " ";//结点显示名称
        private string strOwnerSection = "";//拥有者
        private string strParent = null;//父节点
        private string strSEQ = null;//结点的序列 相当于id
        public static NameValueList Variables;
        public bool Visible = true;

        //添加孩子结点
        public bool AppendChild(KB_List myList)
        {
            if (((myList != null) && this.EnableAddChild()) && (myList.SEQ != this.SEQ))
            {
                if (this.myChildNodes == null)
                {
                    this.myChildNodes = new ArrayList();
                }
                if (myList.Parent != null)
                {
                    myList.Parent.ChildNodes.Remove(myList);
                }
                foreach (KB_List lst in this.myChildNodes)
                {
                    if (myList.ListIndex <= lst.ListIndex)
                    {
                        myList.ListIndex = lst.ListIndex + 1;
                    }
                }
                this.myChildNodes.Add(myList);
                myList.Parent = this;
                myList.OwnerSection = this.OwnerSection;
                myList.SetModified();
                return true;
            }
            return false;
        }

        //添加具体的子项目
        public bool AppendItem(KB_Item myItem)
        {
            if ((myItem != null) && this.EnableAddItem())
            {
                if (this.myItems == null)
                {
                    this.myItems = new ArrayList();
                }
                if (myItem.OwnerList != null)
                {
                    myItem.OwnerList.Items.Remove(myItem);
                }
                foreach (KB_Item item in this.myItems)
                {
                    if (myItem.ListIndex <= item.ListIndex)
                    {
                        myItem.ListIndex = item.ListIndex + 1;
                    }
                }
                this.myItems.Add(myItem);
                myItem.OwnerList = this;
                myItem.SetModified();
                return true;
            }
            return false;
        }

        //名称检查
        public static bool CheckName(string strText)
        {
            if (strText == null)
            {
                return false;
            }
            strText = strText.Trim();
            if ((strText.Length == 0) || (strText.Length > 50))
            {
                return false;
            }
            return true;
        }

        //创建新的KB_List记录
        public override ZYDBRecordBase CreateNewRecord()
        {
            return new KB_List();
        }

        //用户删除 删除KB_List以及下面的item选项
        public override bool CustomDelete(IDbCommand myCmd, ZYDBConnection conn)
        {
            if (this.isKeyEnable())
            {
                myCmd.Parameters.Clear();
                myCmd.CommandText = "Delete From KB_LIST WHERE KB_SEQ=?";
                ZYDBConnection.AddParameter(myCmd, this.strSEQ);
                myCmd.ExecuteNonQuery();
                myCmd.CommandText = "Delete From KB_Item Where KB_SEQ=?";
                myCmd.ExecuteNonQuery();
            }
            return true;
        }

        //判断能否添加子节点
        public bool EnableAddChild()
        {
            return ((!this.HasItems() && StringCommon.isBlankString(this.ListSQL)) && !this.InputBoxAttribute);
        }

        //根据返回值判断能否添加子项目
        public bool EnableAddItem()
        {
            return (!this.HasChildren() && StringCommon.isBlankString(this.ListSQL));
        }


        public int ExecuteSystemItem(ZYDBConnection conn, ArrayList OutItems)
        {
            int CS0000000300000000;
            int iItemCount = OutItems.Count;
            try
            {
                int index;
                ArrayList mySysItems = new ArrayList();
                if ((!StringCommon.isBlankString(this.strListSQL) && (conn != null)) && conn.isOpened())
                {
                    using (IDbCommand myCmd = conn.CreateCommand())
                    {
                        myCmd.CommandText = this.strListSQL;
                        IDataReader myReader = myCmd.ExecuteReader();
                        ArrayList SysItems = new ArrayList();
                        while (myReader.Read())
                        {
                            KB_Item NewItem = new KB_Item();
                            NewItem.ItemStyle = 1;
                            NewItem.OwnerList = this;
                            NewItem.ItemText = myReader.IsDBNull(0) ? "" : myReader.GetString(0);
                            if (myReader.FieldCount > 1)
                            {
                                NewItem.ItemValue = myReader.IsDBNull(1) ? " " : myReader.GetString(1);
                            }
                            else
                            {
                                NewItem.ItemValue = NewItem.ItemText;
                            }
                            if (NewItem.isNormalItem())
                            {
                                OutItems.Add(NewItem);
                            }
                            else
                            {
                                mySysItems.Add(NewItem);
                            }
                            NewItem.DataState = DataRowState.Unchanged;
                        }
                        myReader.Close();
                        myCmd.Parameters.Clear();
                    }
                    conn.ExecuteCompleted();
                }
                if (this.myItems != null)
                {
                    for (int iCount = this.myItems.Count - 1; iCount >= 0; iCount--)
                    {
                        KB_Item myItem = (KB_Item) this.myItems[iCount];
                        if (myItem.isSystemItem())
                        {
                            mySysItems.Add(myItem);
                        }
                        else
                        {
                            OutItems.Insert(0, myItem);
                        }
                    }   
                }
                if (((mySysItems.Count <= 0) || (conn == null)) || !conn.isOpened())
                {
                    goto Label_048F;
                }
                using (IDbCommand myCmd = conn.CreateCommand())
                {
                    foreach (KB_Item mySysItem in mySysItems)
                    {
                        IDataReader myReader2;
                        KB_Item NewItem;
                        switch (mySysItem.ItemStyle)
                        {
                            case 11:
                            {
                                myCmd.CommandText = (Variables == null) ? mySysItem.ItemText : Variables.FixVariableString(mySysItem.ItemText);
                                continue;
                            }
                            case 12:
                            {
                                ZYDBConnection.AddParameter(myCmd, (Variables == null) ? mySysItem.ItemText : Variables.FixVariableString(mySysItem.ItemText));
                                continue;
                            }
                            case 13:
                                myReader2 = myCmd.ExecuteReader();
                                goto Label_02C6;

                            case 14:
                            {
                                myCmd.ExecuteNonQuery();
                                continue;
                            }
                            case 15:
                            {
                                foreach (KB_Item myItem in OutItems)
                                {
                                    if (myItem.ItemText == mySysItem.ItemText)
                                    {
                                        myItem.ItemText = mySysItem.ItemValue;
                                    }
                                }
                                continue;
                            }
                            case 0x10:
                            {
                                foreach (KB_Item myItem in OutItems)
                                {
                                    myItem.ItemText = StringCommon.FormatDateTime(myItem.ItemText, mySysItem.ItemText, mySysItem.ItemValue);
                                }
                                continue;
                            }
                            case 0x11:
                            {
                                KB_Item NewItem2 = new KB_Item();
                                NewItem2.ItemText = (Variables == null) ? mySysItem.ItemText : Variables.FixVariableString(mySysItem.ItemText);
                                OutItems.Add(NewItem2);
                                continue;
                            }
                            case 0x12:
                            {
                                if (Variables != null)
                                {
                                    Variables.SetValue(mySysItem.ItemText, mySysItem.ItemValue);
                                }
                                continue;
                            }
                            case 0x13:
                                goto Label_043D;

                            default:
                            {
                                continue;
                            }
                        }
                    Label_024A:
                        NewItem = new KB_Item();
                        NewItem.OwnerList = this;
                        NewItem.ItemText = myReader2.IsDBNull(0) ? " " : myReader2[0].ToString();
                        if (myReader2.FieldCount > 1)
                        {
                            NewItem.ItemValue = myReader2.IsDBNull(1) ? " " : myReader2[1].ToString();
                        }
                        else
                        {
                            NewItem.ItemValue = NewItem.ItemText;
                        }
                        OutItems.Add(NewItem);
                    Label_02C6:
                        if (myReader2.Read())
                        {
                            goto Label_024A;
                        }
                        myReader2.Close();
                    }
                }
                conn.ExecuteCompleted();
            Label_043D:
                index = 0;
                foreach (KB_Item myItem in OutItems)
                {
                    myItem.ListIndex = index;
                    myItem.DataState = DataRowState.Unchanged;
                    index++;
                }
            Label_048F:
                CS0000000300000000 = OutItems.Count - iItemCount;
            }
            catch (Exception ext)
            {
                MessageBox.Show(null, "程序运行错误\r\n" + ext.ToString(), "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.myItems = new ArrayList();
                this.NewItem("知识库列表加载错误!!!");
                if (conn != null)
                {
                    conn.ExecuteCompleted();
                }
                CS0000000300000000 = 0;
            }
            return CS0000000300000000;
        }

        //通过再数据源执行命令时读取结果集
        public override bool FromReader(IDataReader myReader, ZYDBConnection conn)
        {
            if ((myReader != null) && (myReader.FieldCount >= 9))//判断结果集不为空和判断当前结果集的列数>=9
            {
                //从结果集中取出数据给变量赋值
                this.strSEQ = myReader.IsDBNull(0) ? null : myReader.GetDecimal(0).ToString();//把数据库中第一列的值赋给strSEQ myReader.GetString(0)
                this.strParent = myReader.IsDBNull(1) ? null : myReader.GetDecimal(1).ToString();//myReader.GetString(1)
                this.Islist = myReader.IsDBNull(20) ? 0 : Convert.ToInt32(myReader.GetDecimal(20));
                if (StringCommon.isBlankString(this.strSEQ))//如果变量strSEQ是空白字符 返回null
                {
                    this.strSEQ = null;
                }
                if (StringCommon.isBlankString(this.strParent))
                {
                    this.strParent = null;
                }
                this.strName = myReader.IsDBNull(2) ? " " : myReader.GetString(2);
                //this.strDesc = myReader.IsDBNull(3) ? " " : myReader.GetString(3);
                //this.intListIndex = myReader.IsDBNull(20) ? -1 : Convert.ToInt32(myReader[20]);
                //this.strListSQL = myReader.IsDBNull(5) ? " " : myReader.GetString(5);
                //this.intKBStyle = myReader.IsDBNull(6) ? 0 : Convert.ToInt32(myReader[6]);
                //this.OwnerSection = myReader.IsDBNull(7) ? "" : myReader.GetString(7).Trim();
                //this.KBGroup = myReader.IsDBNull(8) ? "" : myReader.GetString(8).Trim();
                if (StringCommon.isBlankString(this.strOwnerSection))
                {
                    this.strOwnerSection = null;
                }
                if (StringCommon.isBlankString(this.strKBGroup))
                {
                    this.strKBGroup = null;
                }
                if (myReader.FieldCount == 10)
                {
                    this.bolShowInTree = myReader.IsDBNull(9) || (myReader.GetString(9) != "0");
                }
                else
                {
                    this.bolShowInTree = true;
                }
                return true;
            }
            return false;
        }


        ////通过再数据源执行命令时读取结果集
        //public override bool FromReader(DataSet  myDs, IDbConnection  conn)
        //{
        //    if (myDs != null)
        //    {
        //        this .strSEQ = myDs .Tables [0].Rows [0][""].ToString ();
        //    }

        //    if ((myReader != null) && (myReader.FieldCount >= 9))//判断结果集不为空和判断当前结果集的列数>=9
        //    {
        //        //从结果集中取出数据给变量赋值
        //        this.strSEQ = myReader.IsDBNull(0) ? null : myReader.GetDecimal(0).ToString();//把数据库中第一列的值赋给strSEQ myReader.GetString(0)
        //        this.strParent = myReader.IsDBNull(1) ? null : myReader.GetDecimal(1).ToString();//myReader.GetString(1)
        //        if (StringCommon.isBlankString(this.strSEQ))//如果变量strSEQ是空白字符 返回null
        //        {
        //            this.strSEQ = null;
        //        }
        //        if (StringCommon.isBlankString(this.strParent))
        //        {
        //            this.strParent = null;
        //        }
        //        this.strName = myReader.IsDBNull(2) ? " " : myReader.GetString(2);
        //        //this.strDesc = myReader.IsDBNull(3) ? " " : myReader.GetString(3);
        //        this.intListIndex = myReader.IsDBNull(20) ? -1 : Convert.ToInt32(myReader[20]);
        //        //this.strListSQL = myReader.IsDBNull(5) ? " " : myReader.GetString(5);
        //        //this.intKBStyle = myReader.IsDBNull(6) ? 0 : Convert.ToInt32(myReader[6]);
        //        //this.OwnerSection = myReader.IsDBNull(7) ? "" : myReader.GetString(7).Trim();
        //        //this.KBGroup = myReader.IsDBNull(8) ? "" : myReader.GetString(8).Trim();
        //        if (StringCommon.isBlankString(this.strOwnerSection))
        //        {
        //            this.strOwnerSection = null;
        //        }
        //        if (StringCommon.isBlankString(this.strKBGroup))
        //        {
        //            this.strKBGroup = null;
        //        }
        //        if (myReader.FieldCount == 10)
        //        {
        //            this.bolShowInTree = myReader.IsDBNull(9) || (myReader.GetString(9) != "0");
        //        }
        //        else
        //        {
        //            this.bolShowInTree = true;
        //        }
        //        return true;
        //    }
        //    return false;
        //}

        //从XML中得到知识库中个节点的信息包括id，父节点id，名称、单位、sql语句等
        public bool FromXML(XmlElement myElement)
        {
            this.strSEQ = myElement.GetAttribute("seq");
            this.strParent = myElement.GetAttribute("parent");
            this.strName = myElement.GetAttribute("name");
            this.strDesc = myElement.GetAttribute("desc");
            this.intListIndex = Convert.ToInt32(myElement.GetAttribute("index"));
            this.strListSQL = myElement.GetAttribute("sql");
            this.intKBStyle = Convert.ToInt32(myElement.GetAttribute("style"));
            this.OwnerSection = myElement.GetAttribute("section");
            this.strKBGroup = myElement.GetAttribute("group");
            return true;
        }

        //获得知识点的路径 在状态栏上显示
        public string GetRealFullPath()
        {
            string strPath = this.strName;
            for (KB_List p = this.Parent; (p != null) && (p.SEQ != null); p = p.Parent)
            {
                strPath = p.Name + "." + strPath;
            }
            return strPath;
        }

        //查询sql
        public static string GetSelectSQL()
        {
            return "Select * from TABLE_F";//KB_SEQ, KB_PARENT , KB_NAME , KB_DESC , ListIndex , ListSQL , KB_Style , OwnerSection , KB_Group From KB_List ";
        }

        //表名
        public override string GetTableName()
        {
            return "TABLE_F";
        }

        //得到子项目的名称
        public string GetValue()
        {
            if ((this.myItems != null) && (this.myItems.Count > 0))
            {
                return (this.myItems[0] as KB_Item).ItemText;
            }
            return "";
        }

        //判断是否有子节点对象
        public bool HasChildObjects()
        {
            return ((this.HasItems() || this.HasChildren()) || StringCommon.HasContent(this.strListSQL));
        }

        //是否子节点
        public bool HasChildren()
        {
            return ((this.myChildNodes != null) && (this.myChildNodes.Count > 0));
        }

        //是否有具体子选项item
        public bool HasItems()
        {
            return ((this.myItems != null) && (this.myItems.Count > 0));
        }

        public bool HasSystemItem()
        {
            foreach (KB_Item myItem in this.myItems)
            {
                if (myItem.isSystemItem())
                {
                    return true;
                }
            }
            return false;
        }

        public bool isFixItem()
        {
            if ((this.myItems != null) && (this.myItems.Count > 0))
            {
                foreach (KB_Item myItem in this.myItems)
                {
                    if ((myItem.ItemStyle != 0) && (myItem.ItemStyle != 100))
                    {
                        return false;
                    }
                }
                return true;
            }
            return false;
        }

        //判断时候有了key值
        public override bool isKeyEnable()
        {
            return ((this.strSEQ != null) && (this.strSEQ.Length == 10));
        }

        public void LaunchSystemItems(ZYDBConnection conn)
        {
            this.HasLaunchSystemItems = true;
            ArrayList myOutItems = new ArrayList();
            this.ExecuteSystemItem(conn, myOutItems);
            this.myItems = myOutItems;
        }

        //加载所有的子对象
        public void LoadAllChildObjects(ArrayList myList, ZYDBConnection conn)
        {
            if (myList != null)
            {
                if (this.HasChildren())
                {
                    myList.AddRange(this.myChildNodes);//把myChildNodes添加到myList的末尾
                }
                else
                {
                    if (!this.HasLaunchSystemItems)
                    {
                        this.LaunchSystemItems(conn);
                    }
                    if (this.HasItems())
                    {
                        myList.AddRange(this.myItems);
                    }
                }
            }
        }

        //新建一个KB_List
        public KB_List NewChildList(string strName)
        {
            if (!this.EnableAddChild())
            {
                return null;
            }
            if ((this.myItems != null) && (this.myItems.Count > 0))
            {
                return null;
            }
            KB_List NewList = new KB_List();
            NewList.Parent = this;
            NewList.Name = strName;
            NewList.OwnerSection = this.OwnerSection;
            if (this.myChildNodes == null)
            {
                this.myChildNodes = new ArrayList();
            }
            NewList.ListIndex = 0;
            foreach (KB_List myList in this.myChildNodes)
            {
                if (NewList.ListIndex <= myList.ListIndex)
                {
                    NewList.ListIndex = myList.ListIndex + 1;
                }
            }
            this.myChildNodes.Add(NewList);
            NewList.DataState = DataRowState.Added;
            return NewList;
        }

        //新建一个子项目KB_item
        public KB_Item NewItem(string strText)
        {
            if (!this.EnableAddItem())
            {
                return null;
            }
            if ((this.myChildNodes != null) && (this.myChildNodes.Count > 0))
            {
                return null;
            }
            foreach (KB_Item ki in this.myItems)
            {
                if (ki.ItemText.Trim() == strText.Trim())
                {
                    MessageBox.Show("值出现重复！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return null;
                }
            }
            KB_Item NewItem = new KB_Item();
            NewItem.OwnerList = this;
            NewItem.ItemText = strText;
            if (this.myItems == null)
            {
                this.myItems = new ArrayList();
            }
            NewItem.ListIndex = 0;
            foreach (KB_Item myItem in this.myItems)
            {
                if (NewItem.ListIndex <= myItem.ListIndex)
                {
                    NewItem.ListIndex = myItem.ListIndex + 1;
                }
            }
            this.myItems.Add(NewItem);
            NewItem.DataState = DataRowState.Added;
            return NewItem;
        }

        public override bool SetAllocKeyCommand(IDbCommand myCmd, ZYDBConnection conn)
        {
            if (myCmd != null)
            {
                myCmd.CommandText = " Select Max(KB_SEQ) From KB_List ";
                myCmd.Parameters.Clear();
                return true;
            }
            return false;
        }

        //插入记录的命令
        public override bool SetInsertCommnad(IDbCommand myCmd, ZYDBConnection conn)
        {
            if (myCmd != null)
            {
                myCmd.CommandText = "Insert Into KB_List ( KB_SEQ, KB_PARENT , KB_NAME , KB_DESC, ListIndex , ListSQL , KB_Style , OwnerSection , KB_Group) values( ? , ? ,? ,? , ? , ? , ? , ? , ?)";
                myCmd.Parameters.Clear();
                ZYDBConnection.AddParameter(myCmd, this.strSEQ);
                ZYDBConnection.AddParameter(myCmd, this.ParentSEQ);
                ZYDBConnection.AddParameter(myCmd, this.strName);
                ZYDBConnection.AddParameter(myCmd, this.strDesc);
                ZYDBConnection.AddParameter(myCmd, this.intListIndex);
                ZYDBConnection.AddParameter(myCmd, this.strListSQL);
                ZYDBConnection.AddParameter(myCmd, this.intKBStyle);
                ZYDBConnection.AddParameter(myCmd, strDeptment);
                ZYDBConnection.AddParameter(myCmd, (this.strKBGroup == null) ? " " : this.strKBGroup);
                return true;
            }
            return false;
        }

        //设置key值  seq
        public override bool SetKeyWord(string strKey)
        {
            bool CS0000000300000000=false;
            try
            {
                this.strSEQ = strKey;
                CS0000000300000000 = true;
            }
            catch
            {
            }
            return CS0000000300000000;
        }

        //查询所有字段的sql 覆盖了TEKBRecordBase中方法
        public override bool SetSelectAllCommand(IDbCommand myCmd, ZYDBConnection conn)
        {
            myCmd.CommandText = "Select KB_SEQ, KB_PARENT , KB_NAME , KB_DESC , ListIndex , ListSQL , KB_Style , OwnerSection , KB_Group From KB_List  Order by KB_Parent , ListIndex ";
            return true;
        }

        //KB_List 和KBSection联合查询  根据ownersection和kb_seq查询
        public static void SetSelectAllCommandWidthSection(IDbCommand myCmd, string strSection)
        {
            myCmd.CommandText = "Select KB_List.KB_SEQ, KB_List.KB_PARENT , KB_List.KB_NAME , KB_List.KB_DESC , KB_List.ListIndex , KB_List.ListSQL , KB_List.KB_Style , KB_List.OwnerSection , KB_List.KB_Group , KBSection.ShowInTree From KB_List,KBSection where kb_list.kb_seq = kbsection.kb_seq and kbsection.ownersection = ? Order by KB_Parent , ListIndex ";
            myCmd.Parameters.Clear();
            ZYDBConnection.AddParameter(myCmd, strSection);
        }

        //根据kb_Parent查询KB_List表并按照Listindex排序
        public override bool SetSelectCommand(IDbCommand myCmd, ZYDBConnection conn)
        {
            myCmd.CommandText = "Select KB_SEQ, KB_PARENT , KB_NAME , KB_DESC , ListIndex , ListSQL , KB_Style , OwnerSection , KB_Group From KB_List Where kb_Parent =? Order by ListIndex ";
            myCmd.Parameters.Clear();
            ZYDBConnection.AddParameter(myCmd, this.strParent);
            return true;
        }

        //根据kb_seq查询KB_List表
        public override bool SetSelectCommandForOneRecord(IDbCommand myCmd, ZYDBConnection conn)
        {
            myCmd.CommandText = "Select KB_SEQ, KB_PARENT , KB_NAME , KB_DESC , ListIndex , ListSQL , KB_Style , OwnerSection , KB_Group From KB_List Where kb_seq= ? ";
            ZYDBConnection.AddParameter(myCmd, this.strSEQ);
            return true;
        }

        //根据KB_SEQ查询KB_List并按照KB_SEQ排序
        public static void SetSelectSEQCommand(IDbCommand myCmd)
        {
            myCmd.CommandText = "Select KB_SEQ From KB_List Order by KB_SEQ ";
        }
        
        //判断是否已经存在kb_seq
        public override bool SetTestExistCommand(IDbCommand myCmd, ZYDBConnection conn)
        {
            myCmd.CommandText = "select kb_seq from kb_list where kb_seq=" + this.strSEQ;
            return true;
        }

        //根据KB_SEQ更新KB_List
        public override bool SetUpdateCommnad(IDbCommand myCmd, ZYDBConnection conn)
        {
            myCmd.CommandText = "Update KB_LIST set KB_PARENT = ? , KB_NAME = ? , KB_DESC = ? , ListIndex = ? , ListSQL = ?  , KB_Style = ? , OwnerSection = ? , KB_Group = ? WHERE KB_SEQ = ?";
            myCmd.Parameters.Clear();
            ZYDBConnection.AddParameter(myCmd, this.ParentSEQ);
            ZYDBConnection.AddParameter(myCmd, this.strName);
            ZYDBConnection.AddParameter(myCmd, this.strDesc);
            ZYDBConnection.AddParameter(myCmd, this.intListIndex);
            ZYDBConnection.AddParameter(myCmd, this.strListSQL);
            ZYDBConnection.AddParameter(myCmd, this.intKBStyle);
            ZYDBConnection.AddParameter(myCmd, strDeptment);
            ZYDBConnection.AddParameter(myCmd, (this.strKBGroup == null) ? " " : this.strKBGroup);
            ZYDBConnection.AddParameter(myCmd, this.strSEQ);
            return true;
        }

        //
        public void SimpleAppendChild(KB_List myList)
        {
            if (this.myChildNodes == null)
            {
                this.myChildNodes = new ArrayList();
            }
            this.myChildNodes.Add(myList);
            myList.ListIndex = this.myChildNodes.Count;
            myList.Parent = this;
        }

        public void SimpleAppendItem(KB_Item myItem)
        {
            if (this.myItems == null)
            {
                this.myItems = new ArrayList();
            }
            this.myItems.Add(myItem);
            myItem.ListIndex = this.myItems.Count;
            myItem.OwnerList = this;
        }

        //把KB_List的值写在XML文件中 表中每个字段对应一个元素结点
        public bool ToXML(XmlElement myElement)
        {
            myElement.SetAttribute("seq", this.strSEQ);
            myElement.SetAttribute("parent", this.strParent);
            myElement.SetAttribute("name", this.strName);
            myElement.SetAttribute("desc", this.strDesc);
            myElement.SetAttribute("index", this.intListIndex.ToString());
            myElement.SetAttribute("sql", this.strListSQL);
            myElement.SetAttribute("style", this.intKBStyle.ToString());
            myElement.SetAttribute("section", (this.strOwnerSection == null) ? "" : this.strOwnerSection);
            myElement.SetAttribute("group", this.strKBGroup);
            return true;
        }

        public bool AfterAppendNameAttribute
        {
            get
            {
                return CommonFunction.GetIntAttribute(this.intKBStyle, 4);
            }
            set
            {
                this.intKBStyle = CommonFunction.SetIntAttribute(this.intKBStyle, 4, value);
                base.SetModified();
            }
        }

        public ArrayList ChildNodes
        {
            get
            {
                return this.myChildNodes;
            }
            set
            {
                this.myChildNodes = value;
            }
        }

        public string Desc
        {
            get
            {
                return this.strDesc;
            }
            set
            {
                this.strDesc = value;
            }
        }

        public string FullPath
        {
            get
            {
                return this.strFullPath;
            }
            set
            {
                this.strFullPath = value;
            }
        }

        public bool InputBoxAttribute
        {
            get
            {
                return CommonFunction.GetIntAttribute(this.intKBStyle, 1);
            }
            set
            {
                this.intKBStyle = CommonFunction.SetIntAttribute(this.intKBStyle, 1, value);
                base.SetModified();
            }
        }

        public ArrayList Items
        {
            get
            {
                return this.myItems;
            }
            set
            {
                this.myItems = value;
            }
        }

        public string KBGroup
        {
            get
            {
                return this.strKBGroup;
            }
            set
            {
                this.strKBGroup = value;
                base.SetModified();
            }
        }

        public int KBStyle
        {
            get
            {
                return this.intKBStyle;
            }
            set
            {
                this.intKBStyle = value;
                base.SetModified();
            }
        }

        public string KeyPreFix
        {
            get
            {
                if ((this.strSEQ != null) && (this.strSEQ.Length > 3))
                {
                    return this.strSEQ.Substring(0, 3);
                }
                return null;
            }
        }

        public int ListIndex
        {
            get
            {
                return this.intListIndex;
            }
            set
            {
                if (this.intListIndex != value)
                {
                    this.intListIndex = value;
                    base.SetModified();
                }
            }
        }

        public string ListSQL
        {
            get
            {
                return this.strListSQL;
            }
            set
            {
                if (this.strListSQL != value)
                {
                    this.strListSQL = value;
                    base.SetModified();
                }
            }
        }

        public string Name
        {
            get
            {
                return this.strName;
            }
            set
            {
                if (this.strName != value)
                {
                    this.strName = value;
                    if (this.strName == null)
                    {
                        this.strName = " ";
                    }
                    base.SetModified();
                }
            }
        }

        public string OwnerSection
        {
            get
            {
                return this.strOwnerSection;
            }
            set
            {
                this.strOwnerSection = value;
                if (StringCommon.isBlankString(this.strOwnerSection))
                {
                    this.strOwnerSection = null;
                }
                base.SetModified();
            }
        }

        public KB_List Parent
        {
            get
            {
                return this.myParent;
            }
            set
            {
                this.myParent = value;
            }
        }

        public string ParentSEQ
        {
            get
            {
                if (this.myParent == null)
                {
                    return this.strParent;
                }
                return this.myParent.SEQ;
            }
            set
            {
                this.strParent = value;
                base.SetModified();
            }
        }

        public bool PreAppendNameAttribute
        {
            get
            {
                return CommonFunction.GetIntAttribute(this.intKBStyle, 2);
            }
            set
            {
                this.intKBStyle = CommonFunction.SetIntAttribute(this.intKBStyle, 2, value);
                base.SetModified();
            }
        }

        public string SEQ
        {
            get
            {
                return this.strSEQ;
            }
            set
            {
                this.strSEQ = value;
            }
        }

        public bool ShowInTree
        {
            get
            {
                return this.bolShowInTree;
            }
            set
            {
                this.bolShowInTree = value;
            }
        }

        public bool YesNoAttribute
        {
            get
            {
                return CommonFunction.GetIntAttribute(this.intKBStyle, 8);
            }
            set
            {
                this.intKBStyle = CommonFunction.SetIntAttribute(this.intKBStyle, 8, value);
                base.SetModified();
            }
        }

        /// <summary>
        /// 临时的列表值，主要作用在插入药品库的时候记录当前重新选择插入的药品之后存储临时值
        /// </summary>
        private string tempValue = "";

        public string TempValue
        {
            get { return tempValue; }
            set { tempValue = value; }
        }

        /// <summary>
        /// 插入药品库的时候存储临时的痕迹
        /// </summary>
        private string tempSign = "";

        public string TempSign
        {
            get { return tempSign; }
            set { tempSign = value; }
        }

        private int islist;

        public int Islist
        {
            get
            {
                return this.islist;
            }
            set
            {
                this.islist = value;
            }
        }



    }
}

